import Base64url from 'base64url';
let decode = function(token){
    let array = token.split('.');
    let json = Base64url.decode(array[1]);
    let obj = JSON.parse(json);
    if(checkValid(obj.exp)){
        return obj;
    }
    return null;    
}
let checkValid = function(exp){
    //判断时间是否过期
    var ms = Date.now();
    if(ms > exp){
        return false;
    }
    return true;
}
const expobj = {
    decode:decode,
    checkValid:checkValid,
}
export default expobj;
